<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>点击图片获取url</title>
</head>
<body>
<div class="con" id="con">
    <img src="http://i1.sinaimg.cn/ent/d/2008-06-04/U105P28T3D2048907F326DT20080604225106.jpg" alt="">
    <img src="http://img3.cache.netease.com/photo/0001/2010-09-28/6HMTLQ3R00AQ0001.jpg" alt="">
</div>
<script>
    // var div = document.getElementById('con');
    // div.onclick = function (event) {
    //     console.log(event.target.getAttribute('src'));
    // }
    function getUrl() {
        console.log(this);
        console.log(this.getAttribute('src'));
    }
    var imgs = document.getElementsByTagName('img');
    for(var img of imgs) {
        img.onclick = getUrl
    }
</script>
</body>
</html>
